{% extends 'base.html' %}
{% block content %}
<h1>作者列表</h1>
<form method="get" class="row g-3 mb-3">
    <div class="col-auto">
        <input type="text" name="q" class="form-control" placeholder="搜索作者" value="{{ q }}">
    </div>
    <div class="col-auto">
        <button type="submit" class="btn btn-primary">搜索</button>
    </div>
</form>
<a href="{% url 'author-add' %}" class="btn btn-success mb-3">添加新作者</a>
<table class="table table-bordered table-hover bg-white">
    <thead class="table-light">
        <tr>
            <th>姓名</th>
            <th>简介</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
    {% for author in authors %}
        <tr>
            <td>{{ author.name }}</td>
            <td>{{ author.bio }}</td>
            <td>
                <a href="{% url 'author-edit' author.pk %}" class="btn btn-sm btn-info">编辑</a>
                <a href="{% url 'author-delete' author.pk %}" class="btn btn-sm btn-danger">删除</a>
            </td>
        </tr>
    {% empty %}
        <tr><td colspan="3">暂无数据</td></tr>
    {% endfor %}
    </tbody>
</table>
<nav>
    <ul class="pagination">
        {% if authors.has_previous %}
            <li class="page-item"><a class="page-link" href="?q={{ q }}&page=1">首页</a></li>
            <li class="page-item"><a class="page-link" href="?q={{ q }}&page={{ authors.previous_page_number }}">上一页</a></li>
        {% else %}
            <li class="page-item disabled"><span class="page-link">首页</span></li>
            <li class="page-item disabled"><span class="page-link">上一页</span></li>
        {% endif %}
        <li class="page-item active"><span class="page-link">{{ authors.number }}/{{ authors.paginator.num_pages }}</span></li>
        {% if authors.has_next %}
            <li class="page-item"><a class="page-link" href="?q={{ q }}&page={{ authors.next_page_number }}">下一页</a></li>
            <li class="page-item"><a class="page-link" href="?q={{ q }}&page={{ authors.paginator.num_pages }}">末页</a></li>
        {% else %}
            <li class="page-item disabled"><span class="page-link">下一页</span></li>
            <li class="page-item disabled"><span class="page-link">末页</span></li>
        {% endif %}
    </ul>
</nav>
<a href="{% url 'book-list' %}" class="btn btn-secondary mt-3">返回图书列表</a>
{% endblock %} 